Skip to main content

Example: Object-Oriented Programming

Product: CODESYS Development System

This example shows how object-oriented programming can be used. It shows the implementation of a building with different rooms. A visualization is used for better illustration.

_example_img_oop.png

Description

This example shows a building with three different types of rooms. The first type has only one light. The second one has an additional light, while the third one has two lights and additionally displays the temperature. During the day, all lights are on and the temperature is set to 25 °C. At night, all lights are off and the temperature is set at 15 °C. In order to show the conversion from an interface to a function block, the temperature of room six is always set to 35 °C.

Additional information

  • ILight: Interface to set and get the light value

  • IRoom: interface to performing some operations when the daytime or nighttime occurs

  • ITemp: Interface to set and get the temperature

  • RoomType1: This function block implements the ILight and IRoom interfaces. Therefore, all methods of the interfaces have to be implemented. The Operation_Daytime function turns the light on and Operation_Nighttime turns the light off.

  • RoomType2: This function block extends RoomType1 and inherits all methods. The SetLight method is overridden and extended for the additional light.

  • RoomType3: This function block extends RoomType2 and additionally implements the ITemp interface. The Operation_Daytime and Operation_Nighttime methods are overridden and extended with the temperature.

  • CheckFB: Checks the time of day. Each time period lasts five seconds.

  • BuildingManager: Depending on the time of day, the corresponding operations are performed. In addition, the __QUERYINTERFACE function performs a conversion from the ITemp interface to the function block of RoomType3.

  • Visualization: Shows eight rooms of three different types. The light bulbs are turned on during the day and turned off at night. In two rooms, the temperature is also displayed. This value determines the size and color of the bar.

System requirements and restrictions

Programming system

CODESYS Development System (version 3.5.14.0 or higher)

Runtime system

CODESYS Control Win (version 3.5.14.0)

Add-on components

-

Note

_example_icon.png DOWNLOAD Project